//
//  XSJCreateLiveRoomVC.m
//  XSJ
//
//  Created by yuanyuan he on 2020/5/9.
//  Copyright © 2020 apple. All rights reserved.
//

#import "XSJCreateLiveRoomVC.h"
#import "XSJCreateLiveRoomTableCell.h"
#import "SVProgressHUD.h"
#import "MJExtension.h"
#import "TZImagePickerController.h"
#import "UserInfoModel.h"
#import "BRPickerView.h"
#import "TextInputVC.h"
#import "XSJLiveBroadcastTableCell.h"
#import "XSJLiveNowTableCell.h"


@interface XSJCreateLiveRoomVC ()<TextInputVCDelegate,XSJLiveBroadcastTableCellDelegate>

@end

@implementation XSJCreateLiveRoomVC

static NSString *const XSJCreateLiveRoomTableCellID = @"XSJCreateLiveRoomTableCellID";
static NSString *const XSJLiveBroadcastTableCellID = @"XSJLiveBroadcastTableCellID";
static NSString *const XSJLiveNowTableCellID = @"XSJLiveNowTableCellID";


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //    [ZFTool isHiddenNavigationBarSeparatorLine:YES vc:self];
    self.title = @"创建直播间";
    [self setupTableView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(void)viewWillAippear:(BOOL)animated{
    
    [super viewWillAppear:animated];
}

-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    //[self loadData];
}

//加载数据
//-(void)loadData
//{
//    ZWeakSelf
//    [http_my getUserBasic:[UserInfoModel getUID] viewedUserId:[UserInfoModel getUID] success:^(id responseObject)
//
//     {
//         [weakSelf loadData_ok:responseObject];
//
//     } failure:^(NSError *error) {
//
//         [SVProgressHUD showInfoWithStatus:error.domain];
//     }];
//}

//加载数据完成
//-(void)loadData_ok:(id)responseObject
//{
//    if (kObjectIsEmpty(responseObject))
//    {
//        return;
//    }
//
//    //jsonToModel
//    self.userInfo = [UserInfoModel mj_objectWithKeyValues:responseObject];
//
//    [self.tableView reloadData];
//
//}


- (void)setupTableView
{
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.alwaysBounceVertical=NO;
    
    [self.tableView registerClass:[XSJCreateLiveRoomTableCell class] forCellReuseIdentifier:XSJCreateLiveRoomTableCellID];
    [self.tableView registerClass:[XSJLiveBroadcastTableCell class] forCellReuseIdentifier:XSJLiveBroadcastTableCellID];
    [self.tableView registerClass:[XSJLiveNowTableCell class] forCellReuseIdentifier:XSJLiveNowTableCellID];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0)
    {
        return 6;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    
    if (indexPath.section==0)
    {
        XSJCreateLiveRoomTableCell* pcell = [tableView dequeueReusableCellWithIdentifier:XSJCreateLiveRoomTableCellID];
        pcell = [[XSJCreateLiveRoomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:XSJCreateLiveRoomTableCellID];
        if (indexPath.row==0) {
            pcell.title = @"标题";
            pcell.name = @"房间标题（最多30个字符）";
//            if ( kStringIsEmpty(self.userInfo.style) )
//            {
//                pcell.name = @"房间标题（最多30个字符）";
//            }
//            else
//            {
//                pcell.name = self.userInfo.style;
//            }
            pcell.isShowTitleButton = YES;
        }
        else if (indexPath.row==1) {
            pcell.title = @"房间密码";
            pcell.name = @"设置房间密码（选填）";
            pcell.isShowTitleButton = YES;
        }
        else if (indexPath.row==2) {
            pcell.title = @"上麦单价";
            pcell.name = @"120.00 豆/次";
            pcell.isShowTitleButton = YES;
        }
        else if (indexPath.row==3) {
            pcell.title = @"进场价格";
            pcell.name = @"120.00 豆/人";
            pcell.isShowTitleButton = YES;
        }
        else if (indexPath.row==4) {
            pcell.title = @"房间分类";
            pcell.name = @"谈天说地";
            pcell.isShowTitleButton = YES;
        }
        else if (indexPath.row==5) {
            pcell.title = @"直播间封面图";
            pcell.isShowButton = YES;
            pcell.isShowNextButton = NO;
            //pcell.iconURL = self.userInfo.picture;
        }
        cell = pcell;
    }
    else if (indexPath.section==1)
    {
        XSJLiveBroadcastTableCell* cell = [tableView dequeueReusableCellWithIdentifier:XSJLiveBroadcastTableCellID];
        if (cell == nil)
        {
            cell = [[XSJLiveBroadcastTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:XSJLiveBroadcastTableCellID];
        }
        return cell;
    }
    else if (indexPath.section==2)
    {
        XSJLiveNowTableCell* cell = [tableView dequeueReusableCellWithIdentifier:XSJLiveNowTableCellID];
        if (cell == nil)
        {
            cell = [[XSJLiveNowTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:XSJLiveNowTableCellID];
        }
        return cell;
    }
    return cell;
}


//每行的高度是多少
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0)
    {
        if (indexPath.row==5)
        {
            return 120;
        }
    }
    if (indexPath.section==2)
    {
        return 60;
    }
    return 45;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0)
    {
        return 20;
    }
    return 0;
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view = [[UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

#pragma mark - TableViewDelegate
//点击了哪个cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0)
    {
        if (indexPath.row==0)
        {
            //标题
            TextInputVC* vc = [[TextInputVC alloc]init];
            vc.title = @"修改标题";
            vc.defalutPlaceholder = @"请输入标题";
            vc.max_len = 20;
            vc.tagType = indexPath.row;
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else if (indexPath.row==1)
        {
            //房间密码
            TextInputVC* vc = [[TextInputVC alloc]init];
            vc.title = @"修改房间密码";
            vc.defalutPlaceholder = @"请输入房间密码";
            vc.max_len = 20;
            vc.tagType = indexPath.row;
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else if (indexPath.row==2)
        {
            //上麦单价
            TextInputVC* vc = [[TextInputVC alloc]init];
            vc.title = @"上麦单价";
            vc.defalutPlaceholder = @"上麦单价";
            vc.max_len = 20;
            vc.tagType = indexPath.row;
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else if (indexPath.row==3)
        {
            //进场价格
            TextInputVC* vc = [[TextInputVC alloc]init];
            vc.title = @"进场价格";
            vc.defalutPlaceholder = @"进场价格";
            vc.max_len = 20;
            vc.tagType = indexPath.row;
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else if (indexPath.row==4)
        {
            //房间分类
            TextInputVC* vc = [[TextInputVC alloc]init];
            vc.title = @"房间分类";
            vc.defalutPlaceholder = @"房间分类";
            vc.max_len = 20;
            vc.tagType = indexPath.row;
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else if (indexPath.row==5)
        {
            //直播间封面图
            //[self changeIcon];
        }
    }
    else if (indexPath.section==1)
    {
        
    }
    else if (indexPath.section==2)
    {
        
    }
}

//点击了昵称、简介修改界面的保存
- (void)TextInputVCDidSave:(NSString *)text vc:(UIViewController*)vc
{
//    TextInputVC* tvc = (TextInputVC*)vc;
//    if (tvc.tagType==1)
//    {
//        if (kStringIsEmpty(text))
//        {
//            [SVProgressHUD showInfoWithStatus:@"姓名不能为空"];
//            return;
//        }
//        //调接口修改
//        UserInfoModel* m = [[UserInfoModel alloc]init];
//        m.name = text;
//        [self edit:m];
//    }
//    else if (tvc.tagType==6)
//    {
//        //调接口修改
//        UserInfoModel* m = [[UserInfoModel alloc]init];
//        m.style = text;
//        [self edit:m];
//    }
}


//-(void)edit:(UserInfoModel*)m
//{
//    m.ID = self.userInfo.ID;
//    //调修改接口
//    ZWeakSelf
//    [SVProgressHUD showWithStatus:@"正在加载"];
//    [http_my updateUserInfo:m success:^(id responseObject)
//    {
//        [SVProgressHUD dismiss];
//        [weakSelf edit_success:responseObject];
//
//    } failure:^(NSError *error)
//    {
//        [SVProgressHUD showErrorWithStatus:error.localizedDescription];
//    }];
//}

//-(void)edit_success:(id)responseObject
//{
//    [self loadData];
//}

#pragma mark -- 方法
//- (void)changeIcon{
//    ZWeakSelf
//    [[JumpVCTool sharedManager] to_MediaCameraVC:self maxCount:1 isVideo:NO isClip:YES isAlert:YES completion:^(NSArray * _Nonnull array, NSError * _Nonnull error)
//     {
//         if (kArrayIsEmpty(array)==NO)
//         {
//             [weakSelf uploadAvatar:[array firstObject]];
//         }
//     }];
//}
//
//-(void)uploadAvatar:(UIImage*)image
//{
//    UserInfoModel* m = [[UserInfoModel alloc]init];
//    m.ID = self.userInfo.ID;
//    m.imageAvatar = image;
//    ZWeakSelf
//    [SVProgressHUD showWithStatus:@"正在加载"];
//    [http_my uploadAvatar:m success:^(id responseObject)
//     {
//         [SVProgressHUD dismiss];
//         [weakSelf edit_success:responseObject];
//     } failure:^(NSError *error) {
//         [SVProgressHUD showErrorWithStatus:error.domain];
//     }];
//}

//直播协议 1:我已阅读并同意 2:《直播协议》
- (void)XSJLiveBroadcastTableCellDidClick:(int)type
{
    if (type==1)
    {
        //我已阅读并同意
        
    }
    else if (type==2)
    {
        //《直播协议》
        //[JumpVCTool to_WebVC:@"http://kn1.knwlapp.com/mobile/article/detail/id/3.html" title:@"隐私协议" naviVC:self.navigationController];
    }
}


@end
